/**
* Copyright (c) 2007,中企动力华南研发中心
* All rights reserved.
*/

package com.ce.pms.custservice.dao;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;

import java.util.List;

import junit.framework.Assert;

import org.junit.Test;

import com.ce.pms.DBUnitTool;
import com.ce.pms.custservice.model.CustServiceEventDO;
import com.ce.pms.custservice.vo.CustServiceEventSearchVO;
import com.ce.pms.custservice.vo.CustServiceEventVO;
import com.sitechasia.webx.core.support.Page;

/**
 * @author 高嵩 编写日期:2008-12-18
 * 事件管理dao测试类
 */
public class CustServiceEventDaoImplT extends DBUnitTool{

	private ICustServiceEventDao custServiceEventDao =  null;
	/* (non-Javadoc)
	 * @see com.ce.pms.DBUnitTool#setUp()
	 */
	@Override
	public void setUp() throws Exception {
		// TODO Auto-generated method stub
		super.setUp();
		initCustServiceEventDao();
	}

	private void initCustServiceEventDao(){
		if (this.custServiceEventDao==null) {
			this.custServiceEventDao = (ICustServiceEventDao)this.applicationContext.getBean("custServiceEventDao");
		}
		assertNotNull(custServiceEventDao);
	}

	/* (non-Javadoc)
	 * @see com.ce.pms.DBUnitTool#tearDown()
	 */
	@Override
	public void tearDown() throws Exception {
		// TODO Auto-generated method stub
		super.tearDown();
		custServiceEventDao =  null;
	}



	/**
	 * 测试查询客服事件列表
	 * @author 高嵩
	 */
	//@Test
	public void testQueryCustServEventList(){
		System.out.println("查询客服事件列表开始------------------");
		CustServiceEventSearchVO custServiceEventSearchVO = new CustServiceEventSearchVO();
		//事件编号
		custServiceEventSearchVO.setEventNo("SJ20081216001");
//		客户姓名--
		//custServiceEventSearchVO.setOwners("业主A");//支持模湖查询(如:业)
//		房号houseNumber
		//custServiceEventSearchVO.setHouseNumber("1-1A");//支持模湖查询
//		详细地址fullAddress
		//custServiceEventSearchVO.setFullAddress("详细地址1");//支持模湖查询
//		事件性质customerServiceEventNatureDO
		//custServiceEventSearchVO.setCustServEventNatureName(custServEventNatureName)
		assertNotNull(custServiceEventDao);
		List<CustServiceEventDO> list= custServiceEventDao.queryCustServEventList(custServiceEventSearchVO);
		assertNotNull(list);
		assertEquals(list.size(),1);
		for (CustServiceEventDO custServiceEventDO : list) {
			assertEquals(custServiceEventDO.getEventNo(), "SJ20081216001");
			assertEquals(custServiceEventDO.getOwners(), "业主A");
			Assert.assertEquals(custServiceEventDO.getHouseNumber(), "1-1A");
		}
	}

	/**
	 * 按页查询客服事件
	 * @author 高嵩
	 * @param searchVO
	 * @return Page
	 * @roseuid 4943444B01E4
	 */
	@Test
	public void testQueryCustServEventByPage(){
		System.out.println("按页查询客服事件开始------------------");
		CustServiceEventSearchVO custServiceEventSearchVO = new CustServiceEventSearchVO();
		//事件编号
		custServiceEventSearchVO.setEventNo("SJ20081216001");
		custServiceEventSearchVO.setPageNo(new Integer(1));
		custServiceEventSearchVO.setPageSize(new Integer(3));
//		客户姓名--
		//custServiceEventSearchVO.setOwners("业主A");//支持模湖查询(如:业)
//		房号houseNumber
		//custServiceEventSearchVO.setHouseNumber("1-1A");//支持模湖查询
//		详细地址fullAddress
		//custServiceEventSearchVO.setFullAddress("详细地址1");//支持模湖查询
//		事件性质customerServiceEventNatureDO
		//custServiceEventSearchVO.setCustServEventNatureName(custServEventNatureName)
		assertNotNull(custServiceEventDao);
		//List<CustServiceEventDO> list= custServiceEventDao.queryCustServEventList(custServiceEventSearchVO);
		Page page= custServiceEventDao.queryCustServEventByPage(custServiceEventSearchVO);
		assertNotNull(page);
		List datas = page.getResult();
		assertEquals(datas.size(),1);//数据集
		assertEquals(page.getResult().size(), 1);//结果集数
		assertEquals(page.getCurrentPageNo(), 1);//当前页
		assertEquals(page.getTotalCount(), 1);//总数
		assertEquals(page.getTotalPageCount(), 1);//总页数

	}

	/**
	 * 查询关联事件
	 * @author 高嵩
	 * @param searchVO
	 * @return List<CustServiceEventVO>
	 * @roseuid 494345BF0128
	 */
	@Test
	public void testQueryAssociatedCSEventList(){
		CustServiceEventSearchVO custServiceEventSearchVO = new CustServiceEventSearchVO();
		custServiceEventSearchVO.setKeyword(new Long(1));
		custServiceEventSearchVO.setPageNo(new Integer(1));
		custServiceEventSearchVO.setPageSize(new Integer(3));
		List<CustServiceEventVO> cvolist = custServiceEventDao.queryAssociatedCSEventList(custServiceEventSearchVO);
		for(CustServiceEventVO cvo : cvolist){
			assertEquals(cvolist.size(), 3);
			assertNotNull(cvo.getEventNo());//事件编号
			//System.out.println(cvo.getEventNo());
			System.out.println(cvo.getContact());
			assertNotNull(cvo.getKeyword());

			assertNotNull(cvo.getFullAddress());//详细地点
			assertNotNull(cvo.getHouseNumber());//房号
			//assertNotNull(cvo.getContact());//联系人
			//assertNotNull(cvo.getEmergencyDegreeName());//紧急程度
			//System.out.println(cvo.getContact()+"   aaaa");
			assertNotNull(cvo.getCustServEventNatureName());//事件性质
			assertNotNull(cvo.getEventContent());//事件内容
			assertNotNull(cvo.getValidityStr());//有效性
			assertNotNull(cvo.getEventStatuzStr());//事件状态
		}

	}

	/**
	 * 分页查询关联事件
	 * @author 高嵩
	 * @param searchVO
	 * @return Page
	 * @roseuid 4943693E032C
	 */
	@Test
	public void testQueryAssociatedCSEventByPage(){
		CustServiceEventSearchVO custServiceEventSearchVO = new CustServiceEventSearchVO();
		custServiceEventSearchVO.setKeyword(new Long(1));
		custServiceEventSearchVO.setPageNo(new Integer(1));
		custServiceEventSearchVO.setPageSize(new Integer(3));
		Page page =custServiceEventDao.queryAssociatedCSEventByPage(custServiceEventSearchVO);
		assertNotNull(page);
		List datas = page.getResult();
		assertEquals(datas.size(),3);
		assertEquals(page.getResult().size(), 3);
		assertEquals(page.getCurrentPageNo(), 1);
		assertEquals(page.getTotalCount(), 3);
		assertEquals(page.getTotalPageCount(), 1);
	}



	/***
	 * 功能描述:  获取数据库事件编号最大值<br>
	 * @return
	 * Create author:yandawei <br>
	 * Create on:2008-12-17  <br>
	 * Edit author:  <br>
	 * Edit on:    <br>
	 * Why:     <br>
	 */
	@Test
	public void  testGetMaxCustomerServiceEventCodeFromDB(){
		String a = custServiceEventDao.getMaxCustomerServiceEventCodeFromDB();
		Assert.assertNotNull(a);
		assertEquals(a, "SJ20090109008");
	}

	/**
	 * 方法描述:获取某“事件类型”下的“客户事件”数目
	 * @author: 王浩羽
	 * Create on: 2008-12-18
	 * @param eventKindId
	 * @return
	 * Edit author:高嵩
	 * Edit on:
	 * 修改原因:
	 */
	public void atestcountEventsNumber(){

	}
}
